/*
* ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
* Without permission, no one has the right to obtain, disclose or use this software in any way.
*/

package ecarx.xsf.notificationcenter;

import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;

import com.ecarx.sdk.awareness.inter.BaseAbilityCollectorService;
import com.ecarx.sdk.smartscene.DataModel;
import com.ecarx.sdk.smartscene.ServiceModel;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import ecarx.xsf.notificationcenter.manager.NotificationDispatchManager;

/**
 * Created time  : 2020/12/3
 * 能力上报和执行接收的Service
 */
public class AbilityService extends BaseAbilityCollectorService {

    private static final String TAG = "AbilityService";
    private static final String SCENE_PNS_FUNCTION = "IHU_LaunchControl_services_pns_protocol";
    private static final String SCENE_PNS_JSON_STR = "pnsProtocol";
    private Handler mHandler = new Handler();

    private List<ServiceModel> serviceModelList = new ArrayList<>();

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onCallService(final ServiceModel serviceModel) {
        Log.i(TAG, "onCallService");
        if (serviceModel.getId().equals(SCENE_PNS_FUNCTION)) {
            Map<String, DataModel> inputData = serviceModel.getInputData();
            DataModel pnsProtocol = inputData.get(SCENE_PNS_JSON_STR);
            String jsonStr = "";
            if (pnsProtocol != null) {
                jsonStr = pnsProtocol.getValue();
                NotificationDispatchManager.get().sendCardNotification(jsonStr);
            }

            DataModel d = new DataModel();
            d.setId("pnsProtocolResult");
            d.setValue(TextUtils.isEmpty(jsonStr) ? "0" : "1");
            serviceModel.getOutputData().put(d.getId(), d);
            callbackServiceResult(serviceModel);
        }
    }
}
